using MicroMsg.Common.Utils;
using MicroMsg.Manager;
using MicroMsg.Protocol;
using MicroMsg.Resource.@string;
using MicroMsg.Scene;
using MicroMsg.Storage;
using MicroMsg.UI.UserContrl;
using MicroMsg.UI.Util;
using System;
using System.Globalization;
using System.IO.IsolatedStorage;
using System.Windows.Media.Imaging;
namespace MicroMsg.Plugin.QQOfflineMsg
{
	public class QQOfflineMsg : PluginBase
	{
		private const string TAG = "QQOfflineMsg";
		public const string PluginKey = "plugin QQOfflineMsg";
		public const long PluginID = 32772L;
		public const string PluginName = "QQOfflineMsg";
		public const int PluginVersion = 256;
		private static QQOfflineMsg mInstance;
		public override string mTitle
		{
			get
			{
				return strings.Con_Plugin_QQOfflineMsg_Nickname;
			}
		}
		public override BitmapSource mIcon
		{
			get
			{
				return HeadImgMgr.getHeadImage("qmessage", true);
			}
		}
		public override BitmapSource mIconHD
		{
			get
			{
				return HeadImgMgr.getHeadImage("qmessage", true);
			}
		}
		public override BitmapSource mIconInList
		{
			get
			{
				return HeadImgMgr.getHeadImage("qmessage", true);
			}
		}
		public override string mDescription
		{
			get
			{
				return strings.Con_Plugin_QQOfflineMsg_Intro;
			}
		}
		public override string mAuthor
		{
			get
			{
				return "tencent";
			}
		}
		public QQOfflineMsg()
		{
			this.mKey = "plugin QQOfflineMsg";
			this.mID = 32772L;
			this.mName = "QQOfflineMsg";
			this.mUserName = "qmessage";
			this.mVersion = 256;
			this.mIndexInTab = MainTabIndex.ContactTab;
			this.mIndexInGroup = 2;
			this.mIndexInPosition = 0;
			this.mProtocolPluginFlag = EPluginFlag.MM_QMSG_UNINSTALL;
			this.mDefaultInstalled = true;
			this.mEnabled = true;
			QQOfflineMsg.mInstance = this;
			if (AccountMgr.getCurAccount().nBindQQ <= 0u)
			{
				RegionInfo currentRegion = RegionInfo.get_CurrentRegion();
				if (currentRegion.get_Name() != "CN")
				{
					this.mEnabled = false;
					this.mDefaultInstalled = false;
				}
			}
		}
		public override PluginSettingBaseCtrl GetPluginSettingCtrl()
		{
			return new QQOfflineMsgPluginSetCtrl();
		}
		public static QQOfflineMsg getInstance()
		{
			return QQOfflineMsg.mInstance;
		}
		public override void onRegisterResult(RetConst retConst_0, int code)
		{
			Log.smethod_4("QQOfflineMsg", string.Concat(new object[]
			{
				"on register result , ret = ",
				retConst_0,
				", code = ",
				code
			}));
		}
		public override bool onInitialize()
		{
			Log.smethod_4("QQOfflineMsg", "initialize. ");
			using (IsolatedStorageFile userStoreForApplication = IsolatedStorageFile.GetUserStoreForApplication())
			{
				string pluginPath = StorageIO.getPluginPath("QQOfflineMsg");
				string text = StorageIO.getPluginPath("QQOfflineMsg") + "/image";
				string text2 = StorageIO.getPluginPath("QQOfflineMsg") + "/voice";
				string text3 = StorageIO.getPluginPath("QQOfflineMsg") + "/video";
				string text4 = StorageIO.getPluginPath("QQOfflineMsg") + "/thumbnail";
				string text5 = StorageIO.getPluginPath("QQOfflineMsg") + "/thumbVideo";
				if (!userStoreForApplication.DirectoryExists(pluginPath))
				{
					userStoreForApplication.CreateDirectory(pluginPath);
				}
				if (!userStoreForApplication.DirectoryExists(text))
				{
					userStoreForApplication.CreateDirectory(text);
				}
				if (!userStoreForApplication.DirectoryExists(text2))
				{
					userStoreForApplication.CreateDirectory(text2);
				}
				if (!userStoreForApplication.DirectoryExists(text3))
				{
					userStoreForApplication.CreateDirectory(text3);
				}
				if (!userStoreForApplication.DirectoryExists(text4))
				{
					userStoreForApplication.CreateDirectory(text4);
				}
				if (!userStoreForApplication.DirectoryExists(text5))
				{
					userStoreForApplication.CreateDirectory(text5);
				}
			}
			return true;
		}
		public override bool onInstalled(InstallMode mode)
		{
			Log.smethod_4("QQOfflineMsg", "on inistalled. ");
			StorageMgr.contact.update(new Contact
			{
				strUsrName = this.mUserName,
				nFlags = 3u,
				nImgFlag = 3u
			});
			AccountMgr.RecvOfflineQQMsg = true;
			ServiceCenter.sceneNewSync.doScene(16, syncScene.MM_NEWSYNC_SCENE_OTHER);
			return true;
		}
		public override bool onUninstalled(InstallMode mode)
		{
			Log.smethod_4("QQOfflineMsg", "on uninstalled. ");
			StorageMgr.contact.update(new Contact
			{
				strUsrName = this.mUserName,
				nFlags = 0u,
				nImgFlag = 3u
			});
			AccountMgr.RecvOfflineQQMsg = false;
			ServiceCenter.sceneNewSync.doScene(16, syncScene.MM_NEWSYNC_SCENE_OTHER);
			QConversationMgr.QQOfflineMsgClearAll();
			return true;
		}
		public override void onAppActivated()
		{
		}
		public override void onAppDeactivated()
		{
		}
		public override bool onParseChatMsg(ChatMsg chatMsg)
		{
			return this.onParseChatTalker(chatMsg.strTalker);
		}
		public override bool onParseChatTalker(string talker)
		{
			return talker.Contains("@qqim");
		}
		public override object execute(int entryType, object args)
		{
			Log.smethod_4("QQOfflineMsg", "plugin execute,   entrytype =" + entryType);
			if (entryType == 2)
			{
				ToolFunction.GotoPageForUserControl("/Source/Plugin/QQOfflineMsg/UI/QQSessionView.xaml", null, false);
			}
			return null;
		}
	}
}
